package com.yangxinquan.test;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

public class MyJFrame2 extends JFrame implements MouseListener {
    public MyJFrame2() {
        Random r = new Random();
        JFrame jF = new JFrame();
        jF.setSize(603, 680);
        jF.setTitle("事件展示");
        //设置关闭模式
        jF.setDefaultCloseOperation(3);
        //关内容默认居中
        jF.setLayout(null);
        //设置置顶
        jF.setAlwaysOnTop(true);
        //设置框居中
        jF.setLocationRelativeTo(null);

        JButton jb = new JButton();
        jb.setText("点击");
        jb.setBounds(100, 120, 100, 50);
        jb.setVisible(true);
        jb.addMouseListener(this);

        jF.add(jb);

        jF.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("点击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("点击不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("点击松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("鼠标划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("鼠标划出");
    }
}
